package com.cyh.structurealgorithm;

import java.util.Arrays;

public class InsertSort {
    public static void test() {
        int arr[] = {3, 9, -1, 10, -2, 5, 10, 3, 11, -8, -2};
        for(int i = 1; i < arr.length; i++) {//从第2个数开始，插入到前面
            int insertVal = arr[i];
            int insertIndex = i - 1;
            while (insertIndex >= 0 && insertVal < arr[insertIndex]) {
                arr[insertIndex + 1] = arr[insertIndex];
                insertIndex--;
            }
            arr[insertIndex + 1] = insertVal;
        }

        System.out.println(Arrays.toString(arr));
    }
}
